﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using AForge.Imaging.Filters;

namespace DM_BlurImage
{
    public partial class Form1 : Form
    {
        private ResourceManager rm;
        
        public Form1()
        {
            InitializeComponent();
            pbPicture.SizeMode=PictureBoxSizeMode.StretchImage;
            cmbLanguage.SelectedIndex = 0;
            rm = en_US.ResourceManager;

        }

        private void changeLanguage(ResourceManager manager)
        {
            btnBlur.Text = manager.GetString("CreateBlur");
            btnSave.Text = manager.GetString("SaveBlur");
            btnLoad.Text = manager.GetString("LoadImage");
            
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog=new OpenFileDialog();
            dialog.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif|BMP Files(*.bmp)|*.bmp|All Files|*.*";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                txtPath.Text = dialog.FileName;
            }

        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            if (txtPath.Text != "")
            {
                pbPicture.Image = Image.FromFile(txtPath.Text);
               
            }
            else
            {
                MessageBox.Show("Please select image file before continue");
            }
        }

        private void btnBlur_Click(object sender, EventArgs e)
        {
            try
            {
                Grayscale filter = new Grayscale(0.275, 0.5, 0.8);
                Bitmap image = filter.Apply((Bitmap) pbPicture.Image);
                IFilter filter2 = new Blur();
                pbPicture.Image = filter2.Apply(image);
                btnSave.Enabled = true;
                btnBlur.Enabled = false;
      
            }
            catch
            {
                MessageBox.Show("Can't blur this image");
                pbPicture.Image = null;
                txtPath.Text = "";
                btnSave.Enabled = false;
                btnBlur.Enabled = false;
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog=new SaveFileDialog();
            dialog.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif|BMP Files(*.bmp)|*.bmp|All Files|*.*";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                pbPicture.Image.Save(dialog.FileName);
                btnSave.Enabled = false;
                pbPicture.Image = null;
                txtPath.Text = "";
                btnBlur.Enabled = false;


            }
        }

        private void pbPicture_Paint(object sender, PaintEventArgs e)
        {
            if (btnSave.Enabled == false&&pbPicture.Image!=null)
            {
                btnBlur.Enabled = true;
            }
            

        }

        private void cmbLanguage_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbLanguage.SelectedIndex == 1)
            {
                rm = am_hy.ResourceManager;

            }
             if (cmbLanguage.SelectedIndex == 0)
            {
                rm = en_US.ResourceManager;

            }
            if (cmbLanguage.SelectedIndex ==2 )
            {
                rm = esp.ResourceManager;

            }

            changeLanguage(rm);
        }
    }
}
